<?php
class Shop extends BZ_Controller
{
    public function _init()
    {
        $this->load->model('cms_block_model','cms_block');
        $this->load->model('tourism_provider_model','tourism_provider');
        $this->load->model('tourism_goods_category_model','tourism_goods_category');
        $this->load->model('advert_model', 'advert');
    }

    /**
     * 站点首页
     */
    public function grid()
    {
        $getData = $this->input->get();
        if(!empty($getData['keyword'])){
            seeHistory($getData['keyword'], $type=2);
        }
        $this->data['advert'] = $this->advert->findByParams(['status'=> 1, 'opentype' => 'link', 'position' => 17], '*', null, 'sort ASC');//头部轮播
        $this->data['category'] = $this->tourism_goods_category->findPrevCategory($level=1,$parent_id=0);
        $this->data['shop'] =  $this->tourism_provider->findProviderByReason($pgNum=13,$num=0,$getData);
        $this->data['pg_flag'] = ($this->data['shop']->num_rows() >=13) ? true : false;
        $this->data['pg'] = 1;
        $this->data['category_id'] = $this->input->get('category_id');
        $this->load->view('tourism/shop/grid', $this->data);
    }

     /**
     *站点搜索页
     */
    public function ajaxShop()
    {
        $pgNum = 13;
        $pg = $this->input->get('pg') ? $this->input->get('pg') : 1;
        $num = ($pg-1)*$pgNum;
        $getData = $this->input->get();
        $data['shop'] = $this->tourism_provider->findProviderByReason($pgNum,$num,$getData);
        echo ($data['shop']->num_rows() > 0) ?
         json_encode(array(
           'status'  => true,
           'pg'      => $pg,
           'num'     => $data['shop']->num_rows(),
           'html'    => $this->load->view('tourism/shop/shoplist',$data,true)
         )) : json_encode(array(
            'status'  => false
        ));exit;
    }

     /**
     * 删除
     */
    public function ajaxClearCookie()
    {
        delete_cookie('historySearch');
        echo json_encode(array('status'=>true));exit;
    }
}